import { reactive } from "vue";


// 修改密码
interface pwdVerify{
  
  password_1: string;
  password_2: string;
  changeType:string
}

export const pwdVerify = reactive<pwdVerify>({
  password_1: "123456",
  password_2: "123456",
  changeType:"pwd",
  
});



interface pwdVerifyRules {
  password_1: ({
    required: boolean;
    message: string;
    trigger: string;
  } | {
    min: number;
    max: number;
    message: string;
    trigger: string;
  })[];
  password_2: ({
    required: boolean;
    message: string;
    trigger: string;

  } | {
    min: number;
    max: number;
    message: string;
    trigger: string;
  
  } | {
    validator: (rule: pwdVerifyRules, value: string, callback: any) => void;
    trigger: string;
  })[];
  
}

const validatePass_2 = (rule:pwdVerifyRules,value:string ,callback:any) => {
  if (value === "") {
    callback(new Error("请再次输入密码"));
  } else if (value !== pwdVerify.password_1) {
    callback(new Error("两次输入密码不一致!"));
  } else {
    callback();
  }
};
export const pwdVerifyRules = reactive<pwdVerifyRules>({
  password_1: [
    {
      required: true,
      message: "请输入你的密码",
      trigger: "blur",
    },
    {
      min: 6,
      max: 20,
      message: "密码长度在6到20个字符",
      trigger: "blur",
    },
  ],
  password_2: [
    {
      required: true,
      message: "请确认你的密码",
      trigger: "blur",
    },
    {
      min: 6,
      max: 30,
      message: "密码长度在6到20个字符",
      trigger: "blur",
    },
    { validator: validatePass_2, trigger: "blur" },
  ],
  
  

});

// 修改邮箱
interface EmailVerify{
  email: string;
  changType: string;
}

export const emailVerify=reactive<EmailVerify>({
  email:"",
  changType:""
})

interface EmailVerifyRules{
  email: {
    type: string;
    message: string;
    required: boolean;
    trigger: string;
}[];
}

export const emailVerifyRules=reactive<EmailVerifyRules>({
  email: [
    {
      type: "email",
      message: "请正确输入邮箱",
      required: true,
      trigger: "blur",
    },
  ],
})
// 修改手机号
interface PhoneVerify{
  phone: string;
    changeType: string;

}

export const phoneVerify=reactive({
  phone:"",
  changeType:""
})
interface phoneVerifyRules{
  phone: ({
    required: boolean;
    message: string;
    trigger: string;
    pattern?: undefined;
} | {
    pattern: RegExp;
    message: string;
    trigger: string;
    required?: undefined;
})[];
}

export const PhoneVerifyRules=reactive<phoneVerifyRules>({
  phone: [
    { required: true, message: "请输入手机号", trigger: "blur" },
    // 这个只能验证手机号
    // { pattern:/^0{0,1}(13[0-9]|15[7-9]|153|156|18[7-9])[0-9]{8}$/, message: "请输入合法手机号", trigger: "blur" }
    { pattern: /^((0\d{2,3}-\d{7,8})|(1[3584]\d{9}))$/, message: "请输入合法手机号/电话号", trigger: "blur" }
  ],
})